{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=998
  Verdict: Accepted
}
var i,n,res,cur,j:longint; a,b:array[0..30001] of longint;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
readln(n);
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
res:=0;
cur:=0;
for i:=1 to n do read(a[i]);
i:=0;
while i<n do begin
  inc(i);
  inc(cur);
  if a[i]<>b[cur] then begin
     if cur<>1 then dec(i);
     res:=i;
    for j:=cur to res do b[j]:=a[j];
    cur:=0;
  end;
  if cur=res then cur:=0;
end;
writeln(res);
end.